package org.anddev.andengine.extension.svg.node;
/**
 * @author Eric Depta
 * @since 01:14:00 - 28.02.2011
 */
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.extension.svg.SVGDoc;
import org.anddev.andengine.extension.svg.util.transform.TransformDoc;
import org.anddev.andengine.util.SAXUtils;
import org.xml.sax.Attributes;

public abstract class DrawablePhysicNode extends TransformableNode {
	protected boolean hasShape = false;
	protected boolean hasPhysic = false;
	protected boolean drawPrimitives = false;
	protected boolean hasSprite = false;
	
	public DrawablePhysicNode(final SVGDoc pSVGDoc){
		super(pSVGDoc);
	}
	
	public void create(final Attributes pAttributes, final TransformDoc pTransform){
		super.create(pAttributes, pTransform);
		this.setHasPhysic(SAXUtils.getBooleanAttribute(pAttributes, TAG_ATTRIBUTE_HASPHYSIC, false));
		this.setHasShape(SAXUtils.getBooleanAttribute(pAttributes, TAG_ATTRIBUTE_HASSHAPE, false));
		this.setDrawPrimitives(SAXUtils.getBooleanAttribute(pAttributes, TAG_ATTRIBUTE_DRAWPRIMITIVE, false));
		
		if(this.isHasPhysic() || this.isHasShape() || this.isDrawPrimitives()){
			final String name = SAXUtils.getAttributeOrThrow(pAttributes, TAG_ATTRIBUTE_ID);
			final Shape shape = this.createShape(name, pAttributes);
			//TODO if valid
			if(this.isHasSprite() || this.isDrawPrimitives()){
				super.mSVGDoc.addShape(name, shape);
			}
			this.createPhysics(shape, name, pAttributes);
		}
	}
	
	protected abstract Shape createShape(final String pName, final Attributes pAttributes);
	protected abstract void createPhysics(final Shape pShape, final String pName, final Attributes pAttributes);
	
	public boolean isHasShape() {
		return this.hasShape;
	}

	public void setHasShape(boolean pHasShape) {
		this.hasShape = pHasShape;
	}

	public boolean isHasPhysic() {
		return this.hasPhysic;
	}

	public void setHasPhysic(boolean pHasPhysic) {
		this.hasPhysic = pHasPhysic;
	}

	public boolean isDrawPrimitives() {
		return this.drawPrimitives;
	}

	public void setDrawPrimitives(boolean pDrawPrimitives) {
		this.drawPrimitives = pDrawPrimitives;
	}

	public boolean isHasSprite() {
		return hasSprite;
	}

	public void setHasSprite(boolean pHasSprite) {
		this.hasSprite = pHasSprite;
	}
}
